IF OBJECT_ID('dbo.GetWeekEndDates') IS NOT NULL
BEGIN
    DROP PROCEDURE dbo.GetWeekEndDates
    IF OBJECT_ID('dbo.GetWeekEndDates') IS NOT NULL
        PRINT '<<< FAILED DROPPING PROCEDURE dbo.GetWeekEndDates >>>'
    ELSE
        PRINT '<<< DROPPED PROCEDURE dbo.GetWeekEndDates >>>'
END
go
-- =======================================================================
-- Procedure Name: dbo.GetWeekEndDates
--
-- Author:      Kevin Cashman, Parallax Consulting LLC
--
-- Create date: 10/22/2008
--
-- Description: Returns list of WeekEnding Dates from 
--		dbo.SubContractDeliverableSnapShot
--
-- Parameters:  None
--              
-- Returns:     INT, 0=Success, -1=Error
--
-- SampleCall:
-- EXECUTE dbo.GetWeekEndDates()
--
--------------------------------------------------------------------------
-- Date        Initials  Modification
--------------------------------------------------------------------------
-- 10/22/08    KC        Created
-- 10/24/08	KC		Added check for 0.
--
-- =======================================================================
CREATE PROCEDURE dbo.GetWeekEndDates
     (@Weeks				INT=NULL ,
     @DomainUserId            INT,
     @Format				INT=101)
AS
BEGIN
     /*  Returned Fields for Dropdown
     --------------------------------
     WeekEndDate		VARCHAR(20)
     */

     -- Initial Settings
     SET NOCOUNT ON
     
     -- Declare Local Variables
     DECLARE   @Error            INT,
               @RowCount         INT
               
	IF @Weeks = 0 SET @Weeks = 500               

	-- Get list
	SELECT	DISTINCT	TOP (ISNULL(@Weeks,500)) CONVERT(VARCHAR(20),WeekEndDate,@Format) AS WeekEndDate
	FROM		dbo.SubContractDeliverableSnapShot
	ORDER BY WeekEndDate DESC


     SELECT @Error=@@ERROR,@RowCount=@@ROWCOUNT
     IF @Error!=0
          RETURN -1

     -- Return Success
     RETURN 0
     
END
go

IF OBJECT_ID('dbo.GetWeekEndDates') IS NOT NULL
    PRINT '<<< CREATED PROCEDURE dbo.GetWeekEndDates >>>'
ELSE
    PRINT '<<< FAILED CREATING PROCEDURE dbo.GetWeekEndDates >>>'
go

GRANT EXECUTE ON dbo.GetWeekEndDates TO InsightReport,Insight
go
